using System;
using System.Linq;
using MvcMall.Core.Domains;
using MvcMall.Core.Enums;
using MvcMall.Data.Repositories;
using MvcMall.Framework.MvcPager;
using NUnit.Framework;

namespace MvcMall.Tests.MvcMallData.Repositories
{
    [TestFixture]
    public class StoreRepositoryTest : ESDatabaseRepositoryTestsBase
    {
        private StoreRepository _storeRepository = new StoreRepository();
        private UserRepository _userRepository = new UserRepository();
        public StoreRepositoryTest()
            : base(true)
        {

        }

        public PagedList<Store> Test(int pageIndex, int pageSize, string userName, string promoteUserName, StoreStatus? storeStatus, StoreType? storeType, string storeName)
        {
            var user = string.IsNullOrEmpty(userName.ToLower()) ? null : _userRepository.GetUser(userName);
            var promoteUser = string.IsNullOrEmpty(promoteUserName.ToLower())
                                  ? null
                                  : _userRepository.GetUser(promoteUserName);

            return _storeRepository.QueryAll()
                .Where(m =>
                       (user == null || m.User == user)
                       && (promoteUser == null || m.PromoteUser == promoteUser)
                       && (storeStatus == null || m.StoreStatus == storeStatus)
                       && (storeType == null || m.StoreType == storeType)
                       && (string.IsNullOrEmpty(storeName) || m.StoreName.ToLower().Contains(storeName.ToLower()))
                ).ToPagedList(pageIndex, pageSize);
        }

        [Test]
        public void TestQuery()
        {
            var result = Test(1, 10, string.Empty, string.Empty,null,null, string.Empty);

            Console.Write(result.Count);
        }
    }
}